//
//  TZYPhotoViewController.m
//  Moment
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 片刻. All rights reserved.
//

#import "TZYPhotoViewController.h"

@interface TZYPhotoViewController ()<UIScrollViewDelegate>

@property (nonatomic, retain) UIScrollView *bigScrollView;
@property (nonatomic, retain) UILabel *imgNumber;
@property (nonatomic, assign) NSInteger num;


@end

@implementation TZYPhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.bigScrollView = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.bigScrollView.backgroundColor = [UIColor blackColor];
    self.bigScrollView.pagingEnabled = YES;
    self.bigScrollView.bounces = NO;
    [self.view addSubview:self.bigScrollView];
   
    //签协议
    self.bigScrollView.delegate = self;
    self.bigScrollView.contentOffset = CGPointMake(self.bigScrollView.width * (self.photoNumber - 1), self.bigScrollView.height);
    
    self.bigScrollView.contentSize = CGSizeMake(self.bigScrollView.width * self.photoArray.count, self.bigScrollView.height);
    for (int i = 0; i < self.photoArray.count; i++) {
        
        //创建小View
        UIScrollView *sonView = [[UIScrollView alloc] initWithFrame:CGRectMake(self.bigScrollView.width/20 + self.bigScrollView.width * i, 0, self.bigScrollView.width - self.bigScrollView.width/10, self.bigScrollView.height)];
        sonView.backgroundColor = [UIColor blackColor];
        [self.bigScrollView addSubview:sonView];
        
        
        UIImageView *photoImgView = [[UIImageView alloc]initWithFrame:sonView.bounds];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",self.photoArray[i]]];
        [photoImgView sd_setImageWithURL:url placeholderImage:PLACEHOLDER_IMAGE];
        [sonView addSubview:photoImgView];
    
        //图片适应原图大小
        photoImgView.contentMode = UIViewContentModeScaleAspectFit;
        //设置代理
        sonView.delegate = self;
    }
    
    
    //页数
    self.imgNumber = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/10, SCREEN_HEIGHT - SCREEN_WIDTH/8, SCREEN_WIDTH/6, SCREEN_WIDTH/20)];
    self.imgNumber.font = [UIFont systemFontOfSize:SCREEN_WIDTH/20];
    self.imgNumber.textColor = [UIColor whiteColor];
    [self.view addSubview:self.imgNumber];
    self.imgNumber.text = [NSString stringWithFormat:@"%ld / %ld", self.photoNumber, self.photoArray.count];
    
    
    //轻拍
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.bigScrollView addGestureRecognizer:tap];
    
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    self.photoNumber = self.bigScrollView.contentOffset.x/self.bigScrollView.width + 1;
    
    self.imgNumber.text = [NSString stringWithFormat:@"%ld / %ld", self.photoNumber, self.photoArray.count];
    
}



-(void)tapAction:(UITapGestureRecognizer *)tap{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
